apiVersion: apps/v1
kind: Deployment
metadata:
  name: ${moduleName}-${version}
  namespace: ${namespace}
  labels:
    service: ${moduleName}
    version: ${version}
spec:
  replicas: ${replicasNum}
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels:
      service: ${moduleName}
      version: ${version}
  template:
    metadata:
      labels:
        service: ${moduleName}
        version: ${version}
        sidecar.istio.io/inject: "true"
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                - key: app
                  operator: In
                  values:
                    - app
                    - java
                    - ${moduleName}
                    - ${productCode}
      containers:
        - name: "app"
          image: "${imageName}"
          imagePullPolicy: Always
          securityContext:
            runAsUser: 0
          env:
            - name: JAVA_OPTS
              value: "${javaArgs}"
            - name: APP_NAME
              value: "${moduleName}"
            - name: TZ
              value: Asia/Shanghai
          resources:
            requests:
              memory: ${minMem}Mi
              ephemeral-storage: ${diskSize}Gi
            limits:
              memory: ${maxMem}Mi
              ephemeral-storage: ${diskSize}Gi
          volumeMounts:
            - name: sfere-time-zone
              mountPath: /etc/localtime
              readOnly: true
            - mountPath: /data/log
              name: java-logs
<#if ready??>
          readinessProbe:
  <#if ready.httpTest??>
            httpGet:
              path: ${ready.httpTest.path}
              port: ${ready.httpTest.port?c}
  </#if>
            initialDelaySeconds: ${ready.initialDelaySeconds}
            periodSeconds: ${ready.periodSeconds}
            timeoutSeconds: ${ready.timeoutSeconds}
            failureThreshold: ${ready.failureThreshold}
</#if>
<#if live??>
          livenessProbe:
  <#if live.httpTest??>
            httpGet:
              path: ${live.httpTest.path}
              port: ${live.httpTest.port?c}
  </#if>
            initialDelaySeconds: ${live.initialDelaySeconds}
            periodSeconds: ${live.periodSeconds}
            timeoutSeconds: ${live.timeoutSeconds}
            failureThreshold: ${live.failureThreshold}
</#if>
        - image: ${imageAddr}/images/filebeat:6.4.2
          imagePullPolicy: Always
          name: filebeat
          command: ["filebeat"]
          args: ["-c", "/etc/filebeat/filebeat.yml"]
          resources:
            requests:
              memory: 64Mi
            limits:
              memory: 256Mi
          env:
            - name: LANG
              value: zh_CN.UTF-8
            - name: moduleName
              value: ${moduleName}
            - name: namespace
              value: ${namespace}
          volumeMounts:
            - mountPath: /data/log
              name: java-logs
            - mountPath: /etc/filebeat
              name: filebeat-config
            - name: sfere-time-zone
              mountPath: /etc/localtime
              readOnly: true
      volumes:
        - name: java-logs
          emptyDir: {}
        - name: filebeat-config
          configMap:
            name: filebeat-config
        - name: sfere-time-zone
          hostPath:
            path: /etc/localtime

